package de.koller.worlders.engine.tiles.landscape.generator;

import de.koller.oceanFramework.util.ColorIntUtil;
import de.koller.worlders.engine.entity.plattform.SolidPlattform;
import de.koller.worlders.engine.entity.zone.topdown.BasicFloor;
import java.awt.image.BufferedImage;

public class LimbLoad implements IGenType {

	private final BufferedImage limb;
	private final int sx, sy, sw, sh;
	private boolean allLight = false;
	
	public LimbLoad( BufferedImage limb, int sx, int sy, int sw, int sh ) {
		this.sx = sx;
		this.sy = sy;
		this.sw = sw;
		this.sh = sh;
		this.limb = limb;
	}
	
	public LimbLoad makeAllLight() {
		allLight = true;
		return this;
	}
	
	@Override
	public BufferedImage generateLight() {
		if( !allLight )
			return null;
		
		BufferedImage li = new BufferedImage( sw, sh, BufferedImage.TYPE_INT_ARGB );
		for( int x = sx; x < sx+sw; x++ )
			for( int y = sy; y < sy+sh; y++ )
				li.setRGB( x-sx, y-sy, 0xffffffff );
		
		return li;
	}

	@Override
	public BufferedImage generateMap() {
		BufferedImage m = new BufferedImage( sw, sh, BufferedImage.TYPE_INT_ARGB );
		
		for( int x = sx; x < sx+sw; x++ )
			for( int y = sy; y < sy+sh; y++ ) {
				int lc = limb.getRGB( x, y );
				int mc = 0x00000000;
				
				if( lc == 0xff000000 )
					mc = ColorIntUtil.getIntColor( SolidPlattform.GEN_ID, 2, 0, 0 );
				if( lc == 0xffffffff )
					mc = 0xffffffff;
				if( lc == 0xff00ff00 )
					mc = ColorIntUtil.getIntColor( BasicFloor.GEN_ID, 0, 0, 0 );
				if( lc == 0xffffff00 )
					mc = ColorIntUtil.getIntColor( BasicFloor.GEN_ID, 1, 0, 0 );
				
				m.setRGB( x-sx, y-sy, mc );
			}
		
		return m;
	}
	
}
